using System.Drawing;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking.Win32;

namespace WeifenLuo.WinFormsUI.Docking
{
    internal class SplitterBase : Control
    {
        public SplitterBase()
        {
            this.SetStyle(ControlStyles.Selectable, false);
        }
        public override DockStyle Dock
        {
            get { return base.Dock; }
            set
            {
                this.SuspendLayout();
                base.Dock = value;
                if(this.Dock == DockStyle.Left || this.Dock == DockStyle.Right){
                    this.Width = this.SplitterSize;
                } else if(this.Dock == DockStyle.Top || this.Dock == DockStyle.Bottom){
                    this.Height = this.SplitterSize;
                } else{
                    this.Bounds = Rectangle.Empty;
                }
                if(this.Dock == DockStyle.Left || this.Dock == DockStyle.Right){
                    this.Cursor = Cursors.VSplit;
                } else if(this.Dock == DockStyle.Top || this.Dock == DockStyle.Bottom){
                    this.Cursor = Cursors.HSplit;
                } else{
                    this.Cursor = Cursors.Default;
                }
                this.ResumeLayout();
            }
        }
        protected virtual int SplitterSize
        {
            get { return 0; }
        }
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            if(e.Button != MouseButtons.Left){
                return;
            }
            this.StartDrag();
        }
        protected virtual void StartDrag() {}
        protected override void WndProc(ref Message m)
        {
            // eat the WM_MOUSEACTIVATE message
            if(m.Msg == (int)Msgs.WM_MOUSEACTIVATE){
                return;
            }
            base.WndProc(ref m);
        }
    }
}